package com.one.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.one.entity.Adder;
import com.one.entity.Education;
import com.one.entity.Major;
import com.one.entity.Teacher;
import com.one.service.AllService;
import com.one.service.TeacherService;

/**
 * 
 * @类描述:教员账户控制层
 * @作者：丁顺
 * @创建时间:2019年4月27日
 * @项目名称:one_upbringcom.one.controller
 */
@Controller
@RequestMapping("teacherController")
public class TeacherController {
	@Resource
	private TeacherService ts;
	@Resource
	private AllService as;
	/**
	 * 登录
	 * @param tAcc
	 * @param tPassword
	 * @param session
	 * @return
	 */
	@RequestMapping("teaLogin")
	@ResponseBody
	public int teaLogin(String tAcc,String tPassword,HttpSession session){
		Map<String, Object> teaLogin = ts.teaLogin(tAcc, tPassword);
		if(null!=teaLogin&&0<teaLogin.size()){
			//登陆成功 去查询所有
			session.setAttribute("teaLogin", teaLogin);
			return 1;
		}
		//登录失败  去登录页面
		return 0;
		
	}
	/**
	 * 去登陆页面
	 * @param model
	 * @return
	 */
	@RequestMapping("toAddJsp")
	public String toAddJsp(Model model){
		//学历
		List<Education> allEducation = as.allEducation();
		model.addAttribute("allEducation", allEducation);
		//专业
		List<Major> allMajor = as.allMajor();
		model.addAttribute("allMajor", allMajor);
		//执教方式
		List<com.one.entity.Model> allModel = as.allModel();
		model.addAttribute("allModel", allModel);
		//执教地区
		List<Adder> allAdder = as.allAdder();
		model.addAttribute("allAdder", allAdder);
		return "addTea";
	}
	/**
	 * 注册
	 * @param teacher
	 * @return
	 */
	@RequestMapping("addTea")	
	public String addTea(Teacher teacher){
		ts.addTeacher(teacher);
		return "../../teaLogin";
	}
	/**
	 * 查询全部教员
	 */
	@RequestMapping("allTea")
	public String allTea(Model model){
		List<Teacher> allTea = ts.allTea();
		model.addAttribute("allTea", allTea);
		return "allTeacher";	
	}
	
	
	
	
	
	
	
	
}
